package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.anno.Log;
import org.example.pojo.Emp;
import org.example.pojo.LoginInfo;
import org.example.pojo.Result;
import org.example.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/login")
public class LoginController{
    @Autowired
    private EmpService empService;

    @Log
    @PostMapping
    public Result login(@RequestBody Emp emp){
        log.info("员工登录：{}", emp);
        LoginInfo login = empService.login(emp);
        if(login != null)
            return Result.success(login);
        return Result.error("用户名或密码错误");
    }
}
